import pickle

from constants import TOTAL_MARK_PATH
from data_process.feature_algorithm.DataAlgorithm import DataAlgorithm
from utils.wav_util import *

class SingleDopplerAlgorithm(DataAlgorithm):

    def __init__(self, wavPath, params):
        super(SingleDopplerAlgorithm, self).__init__(params)
        self.wavPath = wavPath

    def createFeature(self):
        feature = self.getSignalGredientFeature()
        return feature

    def getSignalGredientFeature(self):
        wavPath = self.wavPath
        sonicFreq = self.params.sonicFreq
        lipOffset = self.params.lipOffset
        nfft = self.params.nfft
        frameTime = self.params.frameTime
        aheadTime = self.params.aheadTime
        # timeMark = self.params.timeMark
        #
        # curMark = timeMark[wavPath]

        fs, signalWav = wav.read(wavPath)
        # signalWav = filtAndGetTargetWav(signalWav, 3, sonicFreq, lipOffset, fs)
        Zxx = getSTFT(signalWav, fs, nfft, frameTime, aheadTime)
        Zxx = getTargetFeature(Zxx, sonicFreq, lipOffset, fs, nfft)
        Zxx = SubAdjacent(Zxx)
        Zxx = np.abs(Zxx)
        # Zxx = Zxx ** 2
        time = Zxx.shape[1]
        # Zxx = Zxx[:, curMark[0]:curMark[1]]
        cutNum = 20
        Zxx = Zxx[:,cutNum:Zxx.shape[1]-cutNum]
        return [Zxx]